<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
    <head>
        <th:block th:include="include :: header('请假列表')"/>
    </head>
    <body class="gray-bg">
        <div class="container-div">
            <div class="row">
                <div class="col-sm-12 search-collapse">
                    <form id="formId">
                        <div class="select-list">
                            <ul>
                                <li>
                                    <label style="width: 100px;">流程类别名称：</label>
                                    <select name="flowCategoryInfo.id" id="flowCategoryInfoName">
                                        <option value="">所有</option>
                                        <option th:each="flowCategoryInfo : ${flowCategoryInfoList}" th:text="${flowCategoryInfo.name}" th:value="${flowCategoryInfo.id}"></option>
                                    </select>
                                </li>
                                <li>
                                    <label>审批状态：</label>
                                    <select name="status" th:with="type=${@dict.getType('sys_leave_status')}">
                                        <option value="">所有</option>
                                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                    </select>
                                </li>
                                <li>
                                    <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                                </li>
                            </ul>
                        </div>
                    </form>
                </div>

                <div class="btn-group-sm" id="toolbar" role="group">
                    <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="oa:leave:add">
                        <i class="fa fa-plus"></i> 添加
                    </a>
                </div>
                <div class="col-sm-12 select-table table-striped">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
        <th:block th:include="include :: footer"/>
        <script th:inline="javascript">
            var editFlag = [[${@permission.hasPermi('oa:leave:edit')}]];
            var detailFlag = [[${@permission.hasPermi('oa:leave:detail')}]];
            var removeFlag = [[${@permission.hasPermi('oa:leave:remove')}]];
            var statusDatas = [[${@dict.getType('sys_leave_status')}]];
            var prefix = ctx + "oa/leave";

            $(function () {
                var options = {
                    url: prefix + "/list",
                    createUrl: prefix + "/add",
                    updateUrl: prefix + "/edit/{id}",
                    removeUrl: prefix + "/remove",
                    exportUrl: prefix + "/export",
                    detailUrl: prefix + "/leaveDetail/{id}",
                    modalName: "请假",
                    columns: [{
                        checkbox: true
                    },
                        {
                            field: 'id',
                            title: 'id',
                            visible: false
                        },
                        {
                            field: 'flowCategoryInfo.name',
                            title: '流程类别名称'
                        },
                        {
                            field: 'leaveDays',
                            title: '请假天数'
                        },
                        {
                            field: 'beginDate',
                            title: '开始时间',
                            formatter: function (value, row, index) {
                                return $.common.formatterDate("date", value);
                            }
                        },
                        {
                            field: 'finishDate',
                            title: '结束时间',
                            formatter: function (value, row, index) {
                                return $.common.formatterDate("date", value);
                            }
                        },
                        {
                            field: 'status',
                            title: '审批状态',
                            formatter: function (value, row, index) {
                                return $.table.selectDictLabel(statusDatas, value);
                            }
                        },
                        {
                            field: 'createDate',
                            title: '创建时间',
                            formatter: function (value, row, index) {
                                return $.common.formatterDate("date", value);
                            }
                        },
                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                console.log(row.status);
                                var actions = [];
                                if (row.status == 0) {
                                    actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                } else if (row.status == 1 || row.status == 3 || row.status == 2) {
                                    console.log("123")
                                    actions.push('<a class="btn btn-success btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\',\'true\')"><i class="fa fa-edit"></i>查看详情</a> ');
                                }else{
                                    actions.push('<span>暂无操作</span>');
                                }
                                return actions.join('');
                            }
                        }]
                };
                $.table.init(options);
            });
        </script>
    </body>
</html>